<template>
  <div class="app-container">
    <div class="row row-border-top">
      <div class="cell" style="flex: 1; text-align: center;font-size: 24px;">
        <b>企业资源库管理</b>
      </div>
      <i style="color: #C03639" >温馨提示：资料库可以加入客户公海池，提高筛选有效的客户的效率!</i>
    </div>
    <el-divider></el-divider>

    <el-row :gutter="10" class="mb5">
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="68px"
        class="el-form-search"
      >
        <el-form-item label="公司名称" prop="companyName" class="el-form-search-item">
          <el-input
            v-model="queryParams.companyName"
            placeholder="请输入公司名称"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item class="el-form-search-item">
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </el-row>

    <el-table
      :height="tableHeight"
      v-loading="loading"
      :data="dataList"
      @selection-change="handleSelectionChange"
      ref="dataTable"
    >
      <el-table-column label="#" type="index" width="50" align="center">
        <template scope="scope">
          <span>{{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="公司名称" align="center" prop="companyName" width="180" />
      <el-table-column label="经营范围" align="center" prop="businessScope" width="800" />
      <el-table-column label="联系电话" align="center" prop="phoneNumber" width="180" />
      <el-table-column label="省份" align="center" prop="province"   width="80" />
      <el-table-column label="城市" align="center" prop="city"   width="80" />
      <el-table-column label="区/县" align="center" prop="district"   width="80" />
      <el-table-column label="注册地址" align="center" prop="registeredAddress" width="180" />
      <el-table-column label="行业" align="center" prop="industryCategory" width="180" />
      <el-table-column label="成立日期" align="center" prop="foundationDate" width="120" />
      <el-table-column label="法人" align="center" prop="legalRepresentative"/>
      <el-table-column label="公司类型" align="center" prop="companyType" width="180" />
      <el-table-column label="注册资本" align="center" prop="registeredCapital" width="120"/>
      <el-table-column label="实缴资本" align="center" prop="paidCapital" width="100"/>
      <el-table-column label="核发日期" align="center" prop="approvalDate"   width="120" />
      <el-table-column label="营业日期" align="center" prop="businessDuration" width="170" />
      <el-table-column label="统一信用代码" align="center" prop="unifiedSocialCreditCode" width="180" />
      <el-table-column label="纳税身份识别码" align="center" prop="taxpayerIdentificationNumber" width="180" />
      <el-table-column label="工商编号" align="center" prop="registrationNumber" width="180" />
      <el-table-column label="工商代码" align="center" prop="organizationCode" width="180" />
      <el-table-column label="社会保险员工数量" align="center" prop="numberOfInsured" width="180" />
      <el-table-column label="曾用名" align="center" prop="previousName" width="180" />
      <el-table-column label="最近一次提交年报地址" align="center" prop="latestAnnualReportAddress" width="180" />
      <el-table-column label="网站" align="center" prop="website" width="180" />
      <el-table-column label="备用联系电话" align="center" prop="otherPhoneNumbers" width="180" />
      <el-table-column label="邮箱" align="center" prop="email" width="180" />
      <el-table-column label="备用邮箱" align="center" prop="otherEmails" width="180" />
      <el-table-column label="工商编号" align="center" prop="registrationNumber" width="140" />
      <el-table-column label="经营状态" align="center" prop="operationalStatus"/>
      <el-table-column label="操作"  width="80" align="center" class-name="small-padding fixed-width"  fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-finished" @click="addToPool(scope.row)" v-hasPermi="['crm:pool:receive']">加入公海</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog title="查看资质" :visible.sync="viewFile.preview" width="400px">
    <image-preview
      :src="viewFile.fileUrls"
      :width="60"
      :height="60"
      v-if="viewFile.num>0"
    />
      <p v-if="viewFile.num>0">
      提示：当前共有{{viewFile.num}}张票据，点击图片进行查看！
      </p>
      <p  v-else>
        提示：当前无票据，请先上传后再进行查看！
      </p>
    </el-dialog>
  </div>

</template>

<script>
import {
  list,
  add,
  update,
  del
} from "@/api/transport/company";
import {getUrlByResourceIdAndResourceType} from  "@/api/system/resource";
import { getToken } from "@/utils/auth";
import {addCustomer} from "@/api/crm/customer";
export default {
  name: "HouseRoom",
  dicts: ["sys_notice_status"],
  components: {},
  data() {
    return {
      //时间选择样式
      pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },
      viewFile:{
        fileUrls:'',
        num:'',
        preview:false,
      },
      // 导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地点
        url: process.env.VUE_APP_BASE_API + "/car/fuels/import",
      },
      // 表格高度
      tableHeight: document.documentElement.clientHeight - 180,
      // 遮罩层
      loading: true,
      // 选中id数组
      ids: [],
      //评价列表查询的id
      checkid: null,
      // 选中行数组
      selection: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示更多搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 详情表格数据
      dataList: [],
      // 小区表格数据
      houseVillageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: "create_time",
        isAsc: "desc",
        companyName: null,
      },
      // 表单参数
      form: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
    addToPool(row){
      this.form = {
        code:"A"+row.id,
        name: row.companyName,
        linkman: row.legalRepresentative,
        phone:  row.phoneNumber,
        region: row.city,
        customerIndustry: row.industryCategory,
        customerRank: "C",
        customerStatus: 0,
        status: "2",
        cluesName: null,
        cluesSource: null,
        cluesStatus: null,
        dealStatus: '0',
        owner: null,
        delFlag: 0,
        version: 0,
        remark: null,
      };
      addCustomer(this.form).then((response) => {
        this.$modal.msgSuccess('新增成功')
        this.open = false
        this.getList()
      })
    },
    /** 查询详情列表 */
    getList() {
      this.loading = true;
      list(this.queryParams).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        foundationDate: null,
        businessDuration: null,
        province: null,
        registeredCapital: null,
        paidCapital: null,
        endLocation: null,
        approvalDate: null,
        manager: null,
        unifiedSocialCreditCode: null,
        registrationNumber: null,
        organizationCode: null,
        location: null,
        operationalStatus: null,
        description: null,
        files:null
      };
      this.featureList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.resetForm("queryMoreForm");
      this.handleQuery();
    },
    /** 更多搜索按钮 */
    handleMoreQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.$refs.drawer.closeDrawer();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.selection = selection;
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.form = row;
      this.open = true;
      this.title = "修改";
      getUrlByResourceIdAndResourceType(row.id,'TransportOffer').then((response) => {
        this.form.files = response.msg;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            update(this.form.id,this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            add(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除记录？")
        .then(function () {
          return del(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    viewFiles(row) {
      this.viewFile.preview=true;
      getUrlByResourceIdAndResourceType(row.id,'TransportOffer').then((response) => {
        this.viewFile.fileUrls = response.msg;
        this.viewFile.num=response.msg.length>0?response.msg.split(",").length:0;
      });
    },
    /** 导入 */
    handleImport() {
      this.upload.title = "导入";
      this.upload.open = true;
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    /** 下载模板 */
    handleTemplate() {
      this.download(
        "car/fuels/template",
        {
          ...this.queryParams,
        },
        `加油数据导入模板.xlsx`
      );
    },
    /** 导出按钮 */
    handleExport() {
      this.$confirm("确认导出数据吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        this.download(
          "car/fuels/export",
          {
            ...this.queryParams,
          },
          `加油数据_${new Date().getTime()}.xlsx`
        );
      });
    },
    // 导入操作触发
    handleImportCommand(command) {
      switch (command) {
        case "handleImport":
          this.handleImport();
          break;
        case "handleTemplate":
          this.handleTemplate();
          break;
        case "handleExport":
          this.handleExport();
          break;
        default:
          break;
      }
    },
    // 重新绘制表格，防止抖动与滚动条异常
    setDataTable() {
      this.$nextTick(() => {
        this.$refs.dataTable.doLayout();
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.drawer_content {
  margin: 0 30px;
  .drawer_footer {
    float: right;
    padding-bottom: 40rpx;
  }
}
</style>
